package com.example.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.example.domain.CustomRequire;
import com.example.mapper.CustomRequireMapper;
import com.example.service.CustomRequireService;

import com.example.utils.JsonData;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;


@RestController
@RequestMapping("/custom")
public class CustomRequireController {

    @Autowired
    private CustomRequireService customRequireService;

    @Autowired
    private CustomRequireMapper customRequireMapper;//查询操作不涉及事务所以也可以用 Mapper 层调用
    
    /**
     * 查询所有
     * @return
     */
    @RequestMapping("/findAll")
    public JsonData findAll(){
    	Page<CustomRequire> page = new Page<>(1,20);
        Page<CustomRequire> all = customRequireService.findAll(page);
        return JsonData.buildSuccess(all);
    }

    /**
     * 添加
     * @return
     */
    @RequestMapping(value="/add", method=RequestMethod.POST)

    public Object add(@RequestBody CustomRequire customRequire){
    	System.out.print("我是参数:"+customRequire);
        int id = customRequireService.add(customRequire);
        return JsonData.buildSuccess(id);
    }

    /**
     * 根据id查询
     * @return
     */
    @RequestMapping("/findById")
    public Object findById(Integer id){
        CustomRequire customRequire = customRequireService.findById(id);
        return JsonData.buildSuccess(id);
    }

    /**
     * 更新
     * @return
     */
    @RequestMapping("/update")
    public Object update(CustomRequire customRequire){
        customRequireService.update(customRequire);
        return JsonData.buildSuccess();
    }

    /**
     * 删除
     * @return
     */
    @RequestMapping("/delete")
    public Object delete(Integer id){
    	customRequireService.delete(id);
        return JsonData.buildSuccess();
    }
    /**
     * 审核
     * @param reqMap
     * @return
     */
    @PostMapping("/audit")
    public Object audit(@RequestBody Map<String,Object> reqMap) {
    	String id = reqMap.get("id").toString();
    	String state = reqMap.get("state").toString();
    	customRequireService.audit(id, state);
    	return JsonData.buildSuccess();
    	
    }
    
}
